using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using DAL;
using BUS;
using Utility;

public partial class admin_Themhinhanh : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        int id = int.Parse(Request.QueryString["id"]);
            // Get the HttpFileCollection
            HttpFileCollection hfc = Request.Files;
            for (int i = 0; i < hfc.Count; i++)
            {
                HttpPostedFile hpf = hfc[i];
                if (hpf.ContentLength > 0)
                {                    
                    hpf.SaveAs(Server.MapPath("~/Photos") + "\\" +
                    System.IO.Path.GetFileName(hpf.FileName));

                    System .Drawing .Image img = System .Drawing .Image .FromFile (Server .MapPath ("~/Photos/"+ hpf .FileName) );
                    ImageUtility .MakeThumbnailPhoto (img ,100,100, Server .MapPath ("~/Photos/Thumb/"),hpf .FileName );

                    tbHinhSanPham hinhsp = new tbHinhSanPham();
                    hinhsp.Masp  = id;
                    hinhsp .Tenhinh  = hpf.FileName.ToString();
                    //hinhsp .Duongdan  = "~/Photos/" + hpf.FileName;
                    tbHinhSanPhamBUS.Insert (hinhsp);
                    Response.Write("<b>File: </b>" + hpf.FileName + "  <b>Size:</b> " +
                        hpf.ContentLength + "  <b>Type:</b> " + hpf.ContentType + " Uploaded Successfully <br/>");
                    
                    
                    //// Up 1 cai
                    //string filename = DateTime.Now.Ticks.ToString() + "_" + fu_HinhMinhHoa.FileName;
                    //fu_HinhMinhHoa.SaveAs(Server.MapPath("~/Photos/" + filename));
                    //System.Drawing.Image img = System.Drawing.Image.FromFile(
                    //    Server.MapPath("~/Photos/" + hpf.FileName));
                    //ImageUtility.MakeThumbnailPhoto(
                    //    img, 100, 100, Server.MapPath("~/Photos/Thumb/"), hpf.FileName );
                                   
                }
                
            }
            Response.Redirect("Danhsachsanpham.aspx");
    }

    }

